<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .tab {
            margin: 100px auto 0;
            width: 600px;
        }

        .tab .options {
            border-top: 2px solid #06a86e;
            overflow: hidden;
        }

        .tab .options h3 {
            float: left;
            width: 150px;
            height: 40px;
            line-height: 40px;
            text-align: center;
            font-size: 18px;
            font-weight: normal;
            color: #666;
            background-color: #f7f8f8;
            cursor: pointer;
        }

        .tab .contents {
            padding: 10px 0;
            height: 200px;
            overflow: hidden;
        }

        .tab .contents div {
            overflow: hidden;
            display: none;
            /* margin-bottom: 10px; */
        }

        .tab .contents div img {
            float: left;
            width: 150px;
            height: 200px;
        }

        .tab .options .active {
            background-color: #06a86e;
            color: #fff;
        }

        .tab .contents .show {
            display: block;
        }
    </style>
</head>

<body>
    <!-- 最外层容器 -->
    <div class="tab">
        <!-- 选项区 -->
        <div class="options">
            <!-- <h3 class="active">科幻</h3>
        <h3>爱情</h3>
        <h3>动作</h3>
        <h3>喜剧</h3> -->
        </div>
        <!-- 内容区 -->
        <div class="contents">
            <div class="show">
                <!-- <img src="./e1.png" alt="">
            <img src="./e1.png" alt="">
            <img src="./e1.png" alt="">
            <img src="./e1.png" alt=""> -->
            </div>
        </div>
    </div>
    <script>
        var datas = {
            options: ['科幻', '爱情', '动作', '喜剧'],
            contents: [
                ['./imgs/e1.png', './imgs/e1.png', './imgs/e1.png', './imgs/e1.png'],
                ['./imgs/e2.png', './imgs/e2.png', './imgs/e2.png', './imgs/e2.png'],
                ['./imgs/e3.png', './imgs/e3.png', './imgs/e3.png', './imgs/e3.png'],
                ['./imgs/e4.png', './imgs/e4.png', './imgs/e4.png', './imgs/e4.png']
            ]
        }

        var options = document.querySelector('.options');
        var show = document.querySelector('.show');
        var template1 = '';
        var template2 = '';

        datas.options.forEach(function (item) {
            template1 += '<h3>' + item + '</h3>';
        })
        options.innerHTML = template1;

        options.firstElementChild.className = 'active';
        datas.contents[0].forEach(function (item) {
            template2 += '<img src="' + item + '" alt="">';
        })
        show.innerHTML = template2;

        var prevIndex = 0;

        for (var i = 0; i < options.children.length; i++) {

            options.children[i].index = i;

            options.children[i].onclick = function () {

                options.children[prevIndex].className = '';
                this.className = 'active';
                prevIndex = this.index;

                template2 = '';
                datas.contents[this.index].forEach(function (item) {
                    template2 += '<img src="' + item + '" alt="">';
                })
                show.innerHTML = template2;
            }


        }
    </script>
</body>

</html>